<?php
	/**
	* 角色列表
	*/
?>
	<script src="<?php echo base_url().$this->config->item('public'); ?>assets/js/edit.js"></script>
	<!--list table-->
	
	<table cellspacing="0" class="table table-bordered table-striped">
        <thead>
		<tr><th colspan="5">
          <ul class="toolbar">
            <li><label class="checkbox"><input type="checkbox" id="checkAllBox" onclick="checkAll(this,'checkbox_role')">全选</label></li>
            <li><button class="button button-danger" onclick="del('checkbox_role')"><i class="icon-white icon-trash"></i>批量删除</button></li>
            <li><button class="button button-success" onclick="status('checkbox_role',1)"><i class="icon-white icon-ok"></i>启用</button></li>
            <li><button class="button button-inverse" onclick="status('checkbox_role',0)"><i class="icon-white icon-ban-circle"></i>禁用</button></li>
          </ul>
          </th></tr>
          <tr>
            <th>ID</th>
            <th>角色名</th>
            <th>角色描述</th>
			<th>状态</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
		<?php
			if($roles){
				foreach($roles as $role){
		?>
			  <tr>
				<td><input type='checkbox' name='checkbox_role' value='<?php echo $role['id']?>'/></td>
				<td><?=$role['name']?></td>
				<td><?=$role['content']?></td>
				<td>
				<?php
					switch($role['status']){
						case 0:
				?>
						<a href="javascript:status(<?php echo $role['id']?>,1)"><span class="label label-important" title="点击启用">已禁用</span></a>
				<?php
						
						break;
						case 1:
				?>
						<a href="javascript:status(<?php echo $role['id']?>,0)"><span class="label label-success"  title="点击禁用">已启用</span></a>
				<?php
						break;
					}
				?>
				</td>
				<td><a href="<?php echo site_url('role/edit/'.$role['id'])?>" title='编辑'><i class="icon icon-edit"></i></a>&nbsp;&nbsp;<a href="#" title='禁用'><i class="icon icon-ban-circle"></i></a>&nbsp;&nbsp;<a href="javascript:del(<?php echo $role['id']?>)" title='删除'><i class="icon icon-trash"></a></td>
			  </tr>
		
		<?php
				
				}
			}
		?>
  
			<tr><td  colspan="5">
			<ul class="toolbar pull-left">
            <li><label class="checkbox"><input type="checkbox" id="checkAllBox" onclick="checkAll(this,'checkbox_role')">全选</label></li>
            <li><button class="button button-danger" onclick="del('checkbox_role')"><i class="icon-white icon-trash"></i>批量删除</button></li>
            <li><button class="button button-success" onclick="status('checkbox_role',1)"><i class="icon-white icon-ok"></i>启用</button></li>
            <li><button class="button button-inverse" onclick="status('checkbox_role',0)"><i class="icon-white icon-ban-circle"></i>禁用</button></li>
        
        </ul></td></tr>
        </tbody>
      </table>
	  <!--list table END-->
	  
	  <!--toobar-->
	  <div>

		
		<div class="pagination pull-right">
           <?php echo $this->pagination->create_links();?>
        </div>
	  
	  </div>
	  <!--toobar END-->
<script>


	/**
	*	更新状态
	*	@id 编号 或 编号对应的对象(用于批量操作)
	*	@status 数值代表相关的status 
	*/
	function status(id,status){
		
		ids = id;
		//非数字则为相关对象
		if(isNaN(id)){
			ids = getCheckVlue(id);
			if(ids == ""){
				message('请选择至少一个项目!','warning');
				return false;
			}
		}
		data = {
			'data':{'id':ids,'status':status},
			'url':'<?php echo site_url('role/status/');?>',
		}
		
		r = ajaxEdit(data);
		
		switch(r.error){
			case 0:
			window.location.reload();
			break;
			case 1:
			message(r.content,'error');
			break;
		}
		
	}
	
	
	/**
	*	删除
	*	@id 编号 或 编号对应的对象(用于批量操作)
	*	@status 数值代表相关的status 
	*/
	function del(id){
	
		ids = id;
		//非数字则为相关对象
		if(isNaN(id)){
			
			ids = getCheckVlue(id);
			if(ids == ""){
				message('请选择至少一个项目!','warning');
				return false;
			}
		}
		data = {
			'data':{'id':ids},
			'url':'<?php echo site_url('role/delete/');?>'
		}
		
		BUI.Message.Confirm('删除后不可恢复,确定删除这些角色吗:<br>'+ids,function(){
			
			r = ajaxEdit(data);
			switch(r.error){
				case 0:
				window.location.reload();
				break;
				case 1:
				message(r.content,'error');
				break;
			}
		
        },'question');
	
	}
	

</script>